package com.wswy.wzcx.ui.main.more

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import com.wswy.wzcx.model.convert
import com.wswy.wzcx.model.core.EventTabConfResp
import com.wswy.wzcx.model.home.ExtModule
import com.wswy.wzcx.module.base.BaseViewModel
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class AllModulesViewModel : BaseViewModel() {


    private val tabConfLiveData = MutableLiveData<Map<String,List<ExtModule>>?>()

    override fun autoRegisterEvent(): Boolean {
        return true
    }

    @Subscribe(threadMode = ThreadMode.BACKGROUND, sticky = true)
    fun onEventTabConfResp(resp: EventTabConfResp) {

        resp.tabConfResp?.all?.run {
            tabConfLiveData.postValue(this.convert())
        } ?:kotlin.run {
            tabConfLiveData.postValue(null)
        }

    }

    fun getTabConfLiveData(): LiveData<Map<String, List<ExtModule>>?> = tabConfLiveData

}